package cc.loac.heba.controller;

import cc.loac.heba.service.CheckCodeService;
import cc.loac.heba.tool.LimitRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@Controller
public class CheckCodeController {
    Logger logger = LoggerFactory.getLogger(getClass());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

    @Resource
    CheckCodeService checkCodeService;

    @PostMapping("/checkCode/sendCode")
    @ResponseBody
    @LimitRequest
    public String sendCode(@RequestParam("email") String email,
                           @RequestParam("type") String type) {
        logger.info(email + " SendCode: " + sdf.format(new Date()));
        logger.error(email);
        return checkCodeService.sendCode(email, type);
    }
}
